package CommonInterface;

import java.util.Arrays;
import java.util.Comparator;

/**
 * Creat with IntelliJ IDEA
 * Description
 * User: mamba24
 * Date: 2022-04-11
 * Time: 12:40
 * To BE A Better Person-2020-3-2
 */
class Student2{
    public int id;
    public String name;
    public int score;

    public Student2(int id, String name, int score) {
        this.id = id;
        this.name = name;
        this.score = score;
    }

    @Override
    public String toString() {
        return "Student2{" +
                "id=" + id +
                ", name='" + name + '\'' +
                ", score=" + score +
                '}';
    }
}
class Namecompator implements Comparator<Student2>{
    @Override
    public int compare(Student2 o1, Student2 o2) {
        return o1.name.compareTo(o2.name);
    }
}

class Idcompator implements Comparator<Student2> {

    @Override
    public int compare(Student2 o1, Student2 o2) {
        return o1.id-o2.id;
    }
}

public class TestDemo2 {
    public static void main(String[] args) {
        //建立一个学生类数组
        Student2[] student=new Student2[5];
        student[0]=new Student2(12,"kris",99);
        student[1]=new Student2(22,"k",73);
        student[2]=new Student2(11,"krike",66);
        student[3]=new Student2(2,"Dottie",69);
        student[4]=new Student2(10,"Kobe",90);
        System.out.println(Arrays.toString(student));
        System.out.println("=======================");
        Idcompator idcompator=new Idcompator();
        Arrays.sort(student,idcompator);
        System.out.println(Arrays.toString(student));
        System.out.println("=======================");
        Namecompator namecompator=new Namecompator();
        Arrays.sort(student,namecompator);
        System.out.println(Arrays.toString((student)));

    }
}
